package com.glsc.ngateway.common.api.flowable.dto.demand;

import com.glsc.ngateway.common.api.common.utils.JsonUtil;
import com.glsc.ngateway.common.api.flowable.dto.param.ParamCreateDto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.tomcat.util.buf.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
//@NoArgsConstructor
public class ParamCreateDtoBuilder {

    static final Logger logger = LoggerFactory.getLogger(ParamCreateDtoBuilder.class);

    private String processDefinitionKey;

    private String userid;

    private String sysid;

    private ParamCreateSubDtoContent content;
    private String contentStr;

    private String createComment;

    private Map<String, String> taskAssignee;

    private Map<String, String> conditionalVariable;

    public ParamCreateDtoBuilder() {
        this.processDefinitionKey = "DemandManagement";
        this.content = new ParamCreateSubDtoContent();
        this.taskAssignee = new HashMap<String, String>();
        this.conditionalVariable = new HashMap<String, String>();
    }

    /**
     * 设置流程启动要素信息
     */
    public ParamCreateDtoBuilder setReqStartElemets(DemandManagementDto glRequirement) {

        /*需求标题*/
        this.content.setTitle(glRequirement.getTitle());

        /*需求提出部门*/
        this.content.getDemandSubmit().setDepartment(glRequirement.getRqDepartment());

        /*需求提出人*/
        this.userid = glRequirement.getRqStaff();
        this.content.getDemandSubmit().setStaff(glRequirement.getRqStaff());

        /*需求创建的入口系统*/
        this.sysid = glRequirement.getCreateProject();
        this.content.getDemandSubmit().setSystemId(glRequirement.getCreateProject());

        /*原始需求人*/
        this.content.getDemandSubmit().setOriginalStaff(glRequirement.getOriRqStaff());

        /*需求类别*/
        this.content.getDemandSubmit().setDemandType(glRequirement.getRqType().getNwcode());

        /*需求紧急级别*/
        this.content.getDemandSubmit().setDemandEmergeLevel(glRequirement.getRqUgtLevel().getNwCode());

        /*需求描述*/
        this.content.getDemandSubmit().setDemandDetail(glRequirement.getRqDesc());

        /*需求文档*/
        if (glRequirement.getRqFile() != null) {
            this.content.getDemandSubmit().setDemandDocument(JsonUtil.Obj2Str(glRequirement.getRqFile()));
        }

        /*需求相关Urls*/
        this.content.getDemandSubmit().setDemandUrl(StringUtils.join(glRequirement.getRqUrls()));

        return this;
    }


    public ParamCreateDto build() {
        this.contentStr = JsonUtil.Obj2Str(content);//转成json
        return new ParamCreateDto(this);
    }

}
